import { HttpException, Injectable } from '@nestjs/common';
import { CreateUserDto } from './dto/create-user.dto';
import { UpdateUserDto } from './dto/update-user.dto';
import { InjectRepository } from '@nestjs/typeorm';
import { UserEntity } from './entities/user.entity';
import { Repository, getRepository, InsertResult } from 'typeorm';
import { PageDto } from './dto/page.dto';
// import { Jwt } from 'common/jwt';

@Injectable()
export class UserService {
  constructor(
    @InjectRepository(UserEntity) private userModel: Repository<UserEntity>,
  ) {}
  //  constructor(private jwt :Jwt){}

  //  login(){
  //   return this.jwt.loginSign('12')
  //  }

  async isHave(username: string) {
   return await this.userModel.count({
      where: {
        username: username,
      },
    });
  }
  async createUser(user: CreateUserDto) :Promise<UserEntity> {

    let val = new UserEntity();
    val.username = user.username;
    val.password = user.password;
    let result = await this.userModel.save(val);
     return result
  }

  async findOne(username :string):Promise<UserEntity>{
   return await this.userModel.findOne({where:{username}})
  }

  /**
  * @author nie
  * @description 获取所有用户
  */
 async getAllUser(page :PageDto){
  return {message:'禁用'}
  let {pageNum,pageSize} = page
  const skip = (pageNum - 1) * pageSize;
  let result = this.userModel.findAndCount({
    skip,
    take:pageSize,
  })
   return result
 }
}
